home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / reporter / boxrpt1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  4.3 KB  |  158 lines

  1.  unit Boxrpt1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Reports, StdCtrls, DB, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     procedure Button1Click(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.  
  18.     Procedure ReportInit;
  19.     Procedure ReportDone;
  20.  
  21.     Procedure BetweenPages;
  22.  
  23.     Procedure PrintHeader (     HeaderBand : tFixedReportBand;
  24.                             var Status     : tBandStatus );
  25.  
  26.     Procedure PrintHeader2 (     HeaderBand : tFixedReportBand;
  27.                              var Status     : tBandStatus );
  28.  
  29.     Procedure PrintItem       ( DetailBand  : tFixedReportBand;
  30.                                 var Status  : tBandStatus );
  31.  
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38. Uses PStatus, Printers;
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure tForm1.ReportInit;
  43. Begin
  44.      { prevent user from pressing key while printing }
  45.      Enabled := False;
  46.  
  47.      With PrintStatusForm Do
  48.      Begin
  49.           ProgressGauge.MaxValue := 2;
  50.           ProgressGauge.Progress := 0;
  51.           CurrentPage := 1;
  52.           PrintStatus := 'Printing...';
  53.           PrinterName := Reporter.Printers[Reporter.PrinterIndex];
  54.           Show;
  55.           UpdateStatus;
  56.      End;
  57. End;
  58.  
  59. procedure tForm1.ReportDone;
  60. Begin
  61.      { get rid of the print status dialog and enable the form again }
  62.      Enabled := True;
  63.  
  64.      PrintStatusForm.Close;
  65. End;
  66.  
  67. procedure tForm1.BetweenPages;
  68. Begin
  69.      { replace current header with new header }
  70.      If Reporter.PageNumber = 1 Then
  71.      Begin
  72.           Reporter.AddHeader ( PrintHeader2 );
  73.           Reporter.Orientation := poLandscape;
  74.      End;
  75. End;
  76.  
  77. procedure tForm1.PrintHeader (     HeaderBand : tFixedReportBand;
  78.                                var Status     : tBandStatus );
  79. Begin
  80.      With HeaderBand, Reporter Do
  81.      Begin
  82.           Canvas.Font.Size := 18;
  83.           Canvas.Font.Style := [fsBold];
  84.           BoxTextOut ( 'Header Change Example', ttaBandHCenter + ttaBandVCenter,
  85.                        btBox, 20, 10,
  86.                        stBottomRight, 20 );
  87.      End;
  88. End;
  89.  
  90. procedure tForm1.PrintHeader2 (     HeaderBand : tFixedReportBand;
  91.                                 var Status     : tBandStatus );
  92. Begin
  93.      With HeaderBand, Reporter Do
  94.      Begin
  95.           Canvas.Font.Size := 10;
  96.           Canvas.Font.Style := [fsBold];
  97.           TextOut ( 'Page ' + IntToStr ( Reporter.PageNumber ),
  98.                     ttaTopOfBand + ttaRightMargin );
  99.  
  100.           Canvas.Font.Size := 18;
  101.           BoxTextOut ( 'Orientation Change Example', ttaBandHCenter + ttaBandVCenter,
  102.                        btBox, 20, 2,
  103.                        stBottomRight, 10 );
  104.      End;
  105. End;
  106.  
  107. procedure tForm1.PrintItem   (     DetailBand : tFixedReportBand;
  108.                                var Status     : tBandStatus );
  109. Var
  110.    Offset, Gap : Word;
  111. Begin
  112.      With DetailBand, Reporter Do
  113.      Begin
  114.           Canvas.Brush.Style := bsClear;
  115.           Gap := (Bottom-Top) Div 10;
  116.           For Offset := 0 to 3 Do
  117.               Canvas.Rectangle ( Left   + Offset * Gap,
  118.                                  Top    + Offset * Gap,
  119.                                  Right  - Offset * Gap,
  120.                                  Bottom - Offset * Gap );
  121.  
  122.  
  123.           With PrintStatusForm Do
  124.           Begin
  125.                ProgressGauge.Progress := ProgressGauge.Progress + 1;
  126.                CurrentPage := Reporter.PageNumber;
  127.                UpdateStatus;
  128.           End;
  129.  
  130.  
  131.           { note:  the manual advancement of the page is necessary because
  132.                    I'm not attempting to print below the margin of the
  133.                    detail band (which is normally used to force the
  134.                    report to a new page) }
  135.           If ( PrintStatusForm.Canceled ) Then
  136.              Status := bsAbort
  137.           Else If ( PageNumber = 2 ) Then
  138.              Status := bsDone
  139.           Else
  140.               NewPage;
  141.      End;
  142. End;
  143.  
  144.  
  145. procedure TForm1.Button1Click(Sender: TObject);
  146. begin
  147.      Reporter.OnReportInit   := ReportInit;
  148.      Reporter.OnReportDone   := ReportDone;
  149.      Reporter.OnBetweenPages := BetweenPages;
  150.  
  151.      Reporter.AddHeader ( PrintHeader );
  152.      Reporter.AddDetail ( Nil, PrintItem );
  153.  
  154.      Reporter.Run;
  155. end;
  156.  
  157. end.
  158.